package com.farsight.leo.fssmartlock.net.bases;

import com.farsight.leo.fssmartlock.net.bean.Error;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

public class BaseResponse<T> {


    /**
     * code : 200
     * data : {"email_address":"leoliao2008@164.com","telephone_number":"13726799852","user_id":4,"user_name":"joe","user_type":0}
     * error : {"msg":"Duplicate entry 'joe' for key 'user_name'"}
     */

    private int code;
    private T data;
    private Error error;

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public Error getError() {
        return error;
    }

    public void setError(Error error) {
        this.error = error;
    }

    @Override
    public String toString() {
        return "BaseResponse{" +
                "code=" + code +
                ", data=" + data +
                ", error=" + error +
                '}';
    }

    protected T getT() throws IllegalAccessException, InstantiationException {
        Type type = getClass().getGenericSuperclass();
        Type[] arguments = ((ParameterizedType) type).getActualTypeArguments();
        Class<T> mTClass = (Class<T>) (arguments[0]);
        return mTClass.newInstance();
    }
}
